/*
 * Exploder
 * 
 * Tero Pyylampi (218437), Jussi Tuurinkoski (211594)
 *
 * An engine for updating all the physic objects in the game
 */

#ifndef GAMEPHYSICOBJECTENGINE_H
#define GAMEPHYSICOBJECTENGINE_H

#include "../GameAbstractEngine.h"
#include "../../../Common.h"

#include "Box2D/Box2D.h"

class GamePhysicObject;
class GameConstructionElement;
class GameCamera;
class GameBomb;
class GameBorder;

class GamePhysicObjectEngine : public GameAbstractEngine {
public:
	// default constructor
	GamePhysicObjectEngine();
	// default destructor
	virtual ~GamePhysicObjectEngine();

	// update engine state
	virtual void update( cocos2d::ccTime dt );

	// interface for creating the game world

	// creates the ground object
	void createGroundObject( b2World *world, cocos2d::CCLayer *layer );
	// create building element
	GameConstructionElement *createElementObject( b2World *world, cocos2d::CCLayer *layer, GameCamera *camera, bool editingMode, PhysicObjectItems type, b2Vec2 pos, float rotation = 0, ElementType properties = NEUTRAL );
	// create bomb
	GameBomb *createBombObject( b2World *world, cocos2d::CCLayer *layer, GameCamera *camera, PhysicObjectItems type, b2Vec2 pos );
	// create border object
	GameBorder *createBorderObject( b2World *world, cocos2d::CCLayer *layer, GameCamera *camera, PhysicObjectItems type, b2Vec2 pos );

	// get physic objects
	std::vector< GamePhysicObject* > *getPhysicObjects();

	// find nearest physic object
	GamePhysicObject *findNearestPhysicObject( b2Vec2 worldLoc );
	// find the object which owns this specific body
	GamePhysicObject *findOwnerOfBody( b2Body *body );

	// check whether specific object collides with any of the existing objects
	bool checkIfObjectCollidesWithAnything( b2Body *body );

private:
	// objects in the game
	std::vector< GamePhysicObject* > *mPhysicObjects;
};

#endif